package com.manshutingyu.gateway.handler;

import com.manshutingyu.common.core.dto.CaptchaResultDTO;
import com.manshutingyu.common.core.dto.R;
import com.manshutingyu.gateway.service.CaptchaService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.server.HandlerFunction;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;

/**
 * 验证码获取
 *
 * @author yinyuxia
 */
@Component
public class ValidateCodeHandler implements HandlerFunction<ServerResponse> {
    @Autowired
    private CaptchaService captchaService;

    @Override
    public Mono<ServerResponse> handle(ServerRequest serverRequest) {
        CaptchaResultDTO result = captchaService.getCaptcha();
        return ServerResponse.status(HttpStatus.OK).body(BodyInserters.fromValue(R.success(result)));
    }
}
